package com.xiang.api.mapper;

import java.util.LinkedHashMap;
import java.util.List;

import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

@Mapper
public interface PublicMapper {
  @Select({
      "START TRANSACTION;",
      "${sql}",
      "COMMIT;"
  })
  void safeQuery(@Param("sql") String sql);

  @Update("${sql}")
  int update(@Param(value = "sql") String sql);

  @Select("${sql}")
  void query(@Param(value = "sql") String sqlStr);

  @Select("${sqlStr}")
  List<LinkedHashMap<String, Object>> select(@Param(value = "sqlStr") String sqlStr);

  @Select("select * from information_schema.TABLES where TABLE_SCHEMA=(select database())")
  List<LinkedHashMap<String, Object>> listTable();

  @Select("select * from information_schema.COLUMNS where TABLE_SCHEMA = (select database()) and TABLE_NAME=#{tableName}")
  List<LinkedHashMap<String, Object>> listTableColumn(String tableName);
}
